using IrcBot.Listener;

namespace IrcBot
{
    internal class IrcMessage
    {
        public string OriginalMessage { get; set; }
        public string Message { get; set; }
        public string BotName { get; set; }
        public string Channel { get; set; }
        public string IrcSafeChannel { get; set; }

        public IrcMessage(string originalMessage)
        {
            var words = originalMessage.Split(' ');

            if (words.Length < 3)
            {
                throw new InvalidMessageException("The message is not in the right format. Correct format is \"[botname] [channelname] [message]\".");
            }

            BotName = words[0];
            Channel = words[1].Replace("#", string.Empty);
            IrcSafeChannel = string.Format("#{0}", Channel);
            Message = string.Join(" ", words, 2, words.Length - 2);
            OriginalMessage = originalMessage;
        }

        private IrcMessage()
        { }
    }
}